<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ include file="../../common_header.jsp"%>
<script type="text/javascript">
	//所有的子窗体都需要有一个save函数，当点击弹出窗体的保存按钮时所进行的操作
	function btnSave_click() {
		var fun_ret;
		var file = $('#uploadFile')[0];
		var imagSize =  document.getElementById("uploadFile").files[0];
		if(imagSize != null && imagSize != "" && !isNull( imagSize )){
			imagSize = imagSize.size;
		}
		name = file.value;
		var pic = /.+(.JPEG|.jpeg|.JPG|.jpg|.GIF|.gif|.BMP|.bmp|.PNG|.png)$/;
		var end = name.substr(name.lastIndexOf("."));
		if (name != "" && name != null && end !=".jpg" && end !=".JPEG" && end !=".jpeg" &&end !=".JPG" && end !=".PNG" && end !=".png" ) {
			$.messager.alert("提示", " 您选择的不是图片文件，请重新选择！");
			return false;
		}else{
			if(imagSize > 204800){
					$.messager.alert("错误提示", "图片需要限制在200kb以内！");
			        return false;
			}
		}
		var formData = new FormData($('#formModule')[0]);
		$.ajax(
				{
					url : '${saveUrl}', //server script to process data
					type : 'POST',
					data : formData,
					async: false,
					cache : false,
					contentType : false,
					processData : false,
					dataType:'json',//请求的数据类型
					xhr : function() { // custom xhr
						myXhr = $.ajaxSettings.xhr();
						if (myXhr.upload) { // if upload property exists
							myXhr.upload.addEventListener('progress',
									progressHandlingFunction, false); // progressbar
						}
						return myXhr;

					},
					success : function(data) {
			               if(data.success == 0 )
			               {
			            	   fun_ret = true;
			                  
			               }
			               else
			               {
			            	   top.Ext.Msg.alert("返回提示",data.msg);
			               }
			           },
					error : errorHandler = function(data) {
						$.messager.alert("错误提示", data.msg);
						return false;
					}
				});	
		
return fun_ret;
	}
	function progressHandlingFunction(e) {
		if (e.lengthComputable) {
			$('progress').attr({
				value : e.loaded,
				max : e.total
			});
		}
	}
	
	 $(document).ready(function(){
		//获取当前用户可查看到的部门
		showDataInCombotree('${ctx }/manage/sysDepartment/getAllDepaetment?flag=2',$("#depId"),'${model.sysDepartment.depId}');
		
		 $.ajax({
		    url:"${ctx }/manage/sysRoles/getRoles",
		    type:"post",
		    dataType:"json",
		    success:function(data){
		        $('#id').combobox({ 
		            data:data.rows,
		            valueField:'id', 
		            textField:'roleName',
		            onLoadSuccess: function (data) { //加载完成后,设置选中第一项
		                var val = $(this).combobox("getData");
		              	var tid="0" + "${model.sysRoles.id}";
						var typeId = parseInt(tid);
						for (var item in val[0]) {
						if(typeId > 0)
							{
								$(this).combobox("select", typeId);
							}
						else if(item == "id")
							{
							 	$(this).combobox("select", val[0][item]);
							}
		              
						}
		            }
		        });        
		    }
		});
});
</script>
<style type="text/css">
#formModule table td input{
	width:180px;
	height:25px;
}


</style>
</head>
<body>
	<div style="padding: 1px" align="center">
		<form id="formModule" method="post">
			<input id="userId" type="hidden" name="userId" value="${model.userId }">
            <input id="photo" type="hidden" name="photo" value="${model.photo }">
			<table border="0">
				<!-- <tr height="0">
					<td><c:if test="${!empty model.userId }"><input type="hidden" value="${model.userId }" name="userId"></input></c:if></td>
				</tr> -->
				<tr height="30">
					<td>所属单位：</td>
                    <td><select id="depId" name="sysDepartment.depId" class="easyui-combotree" style="width:180px;height:25px" data-options="required:true,editable:false"></select>
                    </td>
					
				</tr>
				<tr height="30">
					<td>用户角色：</td>
                    <td><select id="id" name="sysRoles.id" 
                    class="easyui-combobox" style="width: 180px;height: 25px;
                    data-options="required:true,editable:false"></select>
                    </td>
					
				</tr>
				<tr height="30">
					<td>用户名称：</td>
					<td><input id="userName" maxlength="10" placeholder="请输入用户名称"
						class="easyui-validatebox textbox" type="text" 
						name="userName" data-options="required:true"
						 value="${model.userName }"></input></td>
				</tr>
				<tr height="30">
					<td>登录名称：</td>
					<td><input id="LOGINNAME" maxlength="11" placeholder="请输入登录名称"
						class="easyui-validatebox textbox" type="text" 
						name="loginName" style="width: 180px;height: 25px " value="${model.loginName }"></input></td>
				</tr>
				<tr height="30">
				<td>登录密码：</td>
                    <td><input id="password" 
                    class="easyui-validatebox textbox" maxlength="16"
                    type="text" name="password"   data-options="required:true" value="${model.password }"
                    <c:if test="${!empty model.password}">style='display:none'</c:if>></input></td>
                </tr>
				<tr height="30">
					<td>手机：</td>
					<td><input id="phone" maxlength="11" placeholder="请输入11位手机号"
						class="easyui-validatebox textbox" type="text" 
						name="phone" onkeyup="value=value.replace(/[^1234567890-]+/g,'')" validType="phone"
						style="width: 180px;height: 25px " value="${model.phone }"></input></td>
				</tr>
				<tr height="30">
					<td>性别：</td>
					<td><select id="sex" name="sex">
							<option value="1" <c:if test="${model.sex==1 }">selected</c:if>>男</option>
							<option value="2" <c:if test="${model.sex==2 }">selected</c:if>>女</option>
					</select></td>	
				</tr>
				
				<tr height="30">
					<td>状态：</td>
					<td><select id="status" name="status">
							<option value="9" <c:if test="${model.status==9 }">selected</c:if>>正常</option>
							<option value="1" <c:if test="${model.status==1 }">selected</c:if>>注销</option>
					</select></td>
				</tr>
				 <tr height="30">
                    <td>头像：</td>
                    <td><input type="file" class="easyui-linkbutton"
						data-options="toggle:true,group:'g2',plain:true"
						accept="image/*" id="uploadFile"
						name="uploadFile" style="width: 200px;" /></td>
                </tr>	
				
			</table>
		</form>
	</div>
</body>
</html>
